package pe.edu.upc.dsd.whereeat.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pe.edu.upc.dsd.whereeat.base.dao.BaseDAO;
import pe.edu.upc.dsd.whereeat.base.service.impl.BaseServiceImpl;
import pe.edu.upc.dsd.whereeat.dao.CalificacionDAO;
import pe.edu.upc.dsd.whereeat.dao.RestaurantDAO;
import pe.edu.upc.dsd.whereeat.domain.Calificacion;
import pe.edu.upc.dsd.whereeat.domain.Restaurant;
import pe.edu.upc.dsd.whereeat.service.RestaurantService;

@Service
public class RestaurantServiceImpl extends BaseServiceImpl<Restaurant, Integer>
		implements RestaurantService {

	@Autowired
	private RestaurantDAO restaurantDAO;
	@Autowired
	private CalificacionDAO calificacionDAO;

	public RestaurantServiceImpl() {
	}

	@Override
	protected BaseDAO<Restaurant, Integer> getBaseDAO() {
		return restaurantDAO;
	}

	@Override
	public List<Restaurant> obtenerRestaurantsPorUsuario(int usuarioId)
			throws Exception {
		List<Restaurant> restaurantList = new ArrayList<Restaurant>();
		List<Calificacion> calificacionList = calificacionDAO
				.obtenerCalificacionPorRestautantsPorUsuario(usuarioId);
		for (Calificacion calificacion : calificacionList) {
			restaurantList.add(calificacion.getRestaurant());
		}
		return restaurantList;
	}

	@Override
	public Restaurant autenticarRestaurant(String username, String pwd)
			throws Exception {
		// TODO Auto-generated method stub
		return restaurantDAO.buscarRestaurantByUsurNameAndPwd(username, pwd);
	}

}
